/*
 * lab2.fx
 *
 * Created on 19.11.2009, 22:12:06
 */

package javafx179labs.stepanov.lab2;

import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.TextBox;
import javafx.scene.control.Button;
import javafx.scene.Node;

/**
 * @author Евгений
 */
var link: String;
var btnArr: Button[] = [];
var btnDel: Button[] = [];
var btnActual: Integer = 0;
var name: String = null;
var nameEdit: Stage;
var edCount: Integer;

var txtBox = TextBox {
        text: "SampleText"
        width: 170
        height: 25
        selectOnFocus: false
        layoutX: 10
        layoutY: 10
}

var txtBoxEd = TextBox {
        text: bind link with inverse
        width: 170
        height: 25
        selectOnFocus: false
        layoutX: 10
        layoutY: 10
}


var btn: Button = Button {
        text: "+"
        width: 25
        height: 25
        layoutX: 190
        layoutY: 10
        action: function(){
        btnActual = 0;
        name = btnArr[0].text;
        while (name != null){
            btnActual++;
            name = btnArr[btnActual].text;
                }
        btnArr[btnActual].text = txtBox.text;
        btnArr[btnActual].visible = true;
        btnDel[btnActual].visible = true;
        }
}

var btnEd: Button = Button {
        text: "Confirm"
        width: 170
        height: 25
        layoutX: 10
        layoutY: 45
        action: function(){
        btnArr[edCount].text = txtBoxEd.text;
        nameEdit.close();
            }
}

for (x in [0..8]){
        btnArr[x] = Button {
                        text: ""
                        layoutX: 10
                        layoutY: 45 + 35*x
                        width: 170
                        height: 25
                        visible: false
                        action: function() {
                            edCount = x;
                            link = btnArr[x].text;
                            nameEdit = Stage {
                                title : "Edit"
                                scene: Scene {
                                    width: 190
                                    height: 80
                                    content: bind contentEd
                                }
                            }
                        }
                }
         btnDel[x] = Button {
                        text: "X"
                        layoutX: 190
                        layoutY: 45 + 35*x
                        width: 25
                        height: 25
                        visible: false
                        action: function() {
                        btnArr[x].text = "";
                        btnArr[x].visible = false;
                        btnDel[x].visible = false;
                        }
                }

        }

var content: Node[] = [txtBox, btn, btnArr, btnDel];
var contentEd: Node[] = [btnEd, txtBoxEd];


Stage {
        title : "Lab 2"
        scene: Scene {
                width: 225
                height: 360
                content: bind content
        }
}

